package com.hdw.common.base;

import com.hdw.common.constant.CommonResultConstant;

public class BaseResult<T> {

    private CommonResultConstant euStatus;

    private String msg;

    private T data;

    public BaseResult() {

    }

    public BaseResult(CommonResultConstant euStatus) {
        this.euStatus = euStatus;
    }

    public BaseResult(CommonResultConstant euStatus,T data) {
        this.euStatus = euStatus;
        this.data = data;
    }

    public static BaseResult success(Object data) {
        BaseResult result = new BaseResult(CommonResultConstant.SUCCESS);
        result.setData(data);
        return result;
    }

    public static BaseResult success(Object data,String msg) {
        BaseResult result = new BaseResult(CommonResultConstant.SUCCESS);
        result.setData(data);
        result.setMsg(msg);
        return result;
    }

    public static BaseResult error(String errMsg) {
        BaseResult result = new BaseResult(CommonResultConstant.ERROR);
        result.setMsg(errMsg);
        return result;
    }

    public static boolean isSuccess(BaseResult result) {
        if(result.getEuStatus().getCode().equals(CommonResultConstant.SUCCESS.getCode())) {
            return true;
        }
        return false;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public CommonResultConstant getEuStatus() {
        return this.euStatus;
    }

    public void setEuStatus(final CommonResultConstant euStatus) {
        this.euStatus = euStatus;
    }

    public Object getData() {
        return this.data;
    }

    public void setData(final T data) {
        this.data = data;
    }
}
